package com.ghost.UI
{
	import com.ghost.model.UI_skin_data;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import flashx.textLayout.elements.InlineGraphicElement;

	public class Ghost_tip extends Sprite
	{
		private var obj:DisplayObject;
		private var tip:Ghost_tip_base;
		public var type_n:int;
		/**
		 *提示类 
		 */		
		public function Ghost_tip(_obj:DisplayObject,source_xml:String,id:String,type:int,color_n:int=0)
		{
			obj = _obj;
			type_n = type;
			//obj.name = id;
			set_type(type,id,source_xml,color_n);
			this.addEventListener(Event.ADDED_TO_STAGE, add_Handler);
			this.addEventListener(Event.REMOVED_FROM_STAGE, remove_Handler);
		}
		private function set_type(n:int,id:String,source_xml:String,color_n:int=0):void
		{
			tip = new UI_skin_data.ghost_tip_model_v[n]() as Ghost_tip_base;
			tip.show(id,source_xml,color_n);
			this.addChild(tip);
		}
		public function change_content(id:String='',str:String='',color_n:int=0):void
		{
			tip.show(id,str,color_n);
		}
		private function add_Handler(e:Event):void
		{
			//this.x = this.parent.mouseX + 10;
			//this.y = this.parent.mouseY + 10;
			stage.addEventListener(MouseEvent.MOUSE_MOVE, move_Handler);
			move_Handler(null);
		}
		private function remove_Handler(e:Event):void
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, move_Handler);
		}
		private function move_Handler(e:MouseEvent):void
		{
			if(obj.stage != null)
			{
				this.x = this.parent.mouseX+10;
				this.y = this.parent.mouseY+10;
			}
			else
			{
				this.parent.removeChild(this);
			}
			if(this.parent != null && stage != null)
			{
				if((this.parent.mouseX)>=(stage.stageWidth-tip.width) && this.parent.mouseX>stage.stageWidth/2)
				{
					this.x = this.parent.mouseX-tip.width-5;
				}
				if((this.parent.mouseY)>=(stage.stageHeight-tip.height))
				{
					this.y = this.parent.mouseY-tip.height;
				}
			}
		}
	}
}